/* 引入mobx  action:动作  observable：装饰器  （useObservable:使数据变为响应式）  */
import { observable, action } from 'mobx';

/* 引入获取试题接口api */
import { getQuestionsType,addInsertQuestionsType,delQuestionsType,getSubjectList,getExamType,addQuestions,getQuestionsList,getCondition,updateQuestions,getExamstudent} from '../service/index';

/* 引入接口类型 */
import { /* AddQuestionItem, */ ConditionItem, UpdateItem, ExamStudent } from '../utils/interface';

/* 引入antd */
import { message } from 'antd';

/*  */

export default class Consumer{

    [key: string]: any

    /* 所有试题类型列表 */
    @observable
    questionsTypeList= [];
    /* 获取所有的课程 */
    @observable
    subjectList = [];
    /* 获取所有的考试类型 */
    @observable
    examTypeList = [];
    /* 获取所有的试题 */
    @observable
    questionsList = [];
    /* 按条件获取试题 */
    /* @observable
    questionsTypeList = []; */
    /* 更新试题  */

    //待批试卷
    @observable
    examstudentList=[];

    /* 获取所有的试题类型 */
    @action
    async getQuestionsTypeAction(){
        /* 发送请求 */
        let result = await getQuestionsType();
        /* console.log('获取所有的试题类型...',result); */
        
        /* 判断 */
        if (result.data){
            this.questionsTypeList = result.data.data;
        }
    };

    /* 获取所有的课程 */
    @action
    async getSubjectListAction(){
        /* 发送请求 */
        let result = await getSubjectList();
        /* console.log('获取所有的课程...',result); */
        
        /* 判断 */
        if (result.data){
            this.subjectList = result.data.data;
        }
    };

    /* 获取所有的考试类型 */
    @action
    async getExamTypeAction(){
        /* 发送请求 */
        let result = await getExamType();
        /* console.log('获取所有的考试类型...',result); */
        
        /* 判断 */
        if (result.data){
            this.examTypeList = result.data.data;
        }
    };

     /* 添加试题接口  */
     @action
     async addQuestionsAction(questions_type_id: string,
        questions_stem: string,
        subject_id: string,
        exam_id: string,
        user_id: string,
        questions_answer: string,
        title: string){
        /*  console.log('addQuestionsAction..',params); */
         
         /* 发送请求 */
         let result:any = await addQuestions(questions_type_id,
            questions_stem,
            subject_id,
            exam_id,
            user_id,
            questions_answer,
            title);
         console.log('添加试题接口...',result.data);

         if(result.data.code===1){
             this.getQuestionsListAction();
            message.success(result.data.msg);
        }
     };

     /* 添加试题类型 */
    @action
    async getAddInsertQuestionsTypeAction(text:string,sort:string){
        /* 发送请求 */
        let result = await addInsertQuestionsType(text,sort);
        /* console.log('添加试题类型...',result.data); */

        if(result.data.code===1){
            this.getQuestionsTypeAction();
            message.success(result.data.msg);
        }
    };

    /* 删除指定的试题类型 */
    @action
    async delQuestionsTypeAction(id:string){
        /* 发送请求 */
        let result = await delQuestionsType(id);
        /* console.log('删除指定的试题类型...',result.data); */
        
        /* 判断 */
        if (result.data.code===1){
            this.getQuestionsTypeAction();
            message.success(result.data.msg)
        }
    }; 

      /* 获取所有的试题 */
    @action
    async getQuestionsListAction(){
        /* 发送请求 */
        let result = await getQuestionsList();
        console.log('获取所有的试题...',result.data);
        

        /* 判断 */
        if (result.data.code===1){
            this.questionsList=result.data.data;
        }
    };

    /* 按条件获取试题 */
    @action
    async getConditionAction(params:ConditionItem){
        console.log(params);
        
        /* 发送请求 */
        let result = await getCondition(params);
        /* console.log('按条件获取试题...',result.data); */
        
        /* 判断 */
        if (result.data.code===1){
            this.questionsList = result.data.data;
            
        }
    };

    /* 更新试题  */
    @action
    async updateQuestionsAction(params:UpdateItem){
        /* 发送请求 */
        let result = await updateQuestions(params);
        console.log('更新试题...',result);
        
        /* 判断 */
        /* if (result.data){
            this.questionsTypeList = result.data;
        } */
    };

    //待批试卷
    @action
    async getExamstudentAction(params?:ExamStudent){
        let result=await getExamstudent(params)
        if(result.data.code===1){
            this.examstudentList=result.data
             
        }
        
    }
}
